package JAVASE518;

import java.util.Random;
import java.util.Scanner;

public class JAVAdoublecolourball {
    public static void main(String[] argc){
        Random r=new Random();
        int[] red=new int[6];
        //红球随机生成6个数
        for (int i = 0; i < red.length; ) {
            int temp=r.nextInt(33);
            if(contains(red,temp)) {
                red[i]=temp;
                i++;
            }
        }
        //蓝球随机生成1个数
        int blue=r.nextInt(16);
        //提示用户买彩票
        System.out.println("请出示您6个红球所代表数字：");
        //用户输入红球数字
        int[] reduser=new int[6];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < reduser.length; i++) {
                int temp = sc.nextInt();
                if (contains(reduser, temp)) {
                    reduser[i] = temp;
                }
            }

        System.out.println("请出示您1个蓝球所代表数字：");
        //用户输入蓝球数字
        int blueuser= sc.nextInt();
        //计算红球猜中数量
        int redident=redcount(red,reduser);
        //计算蓝球猜中数量
        int blueident=bluecount(blue,blueuser);
        //输出奖金
        bonus(redident,blueident);
    }


    //方法1：判断要存入数组的数字是否与数字组内数字重复
    public static boolean contains(int arr[],int num){
        boolean flag=true;
        for (int i = 0; i < arr.length; i++) {
            if(num==arr[i]){
                flag=false;
            }
        }
        return flag;
    }
    //方法2：计算两个数组中相等数字的个数（红球）
    public static int redcount(int[] arr1,int[] arr2){
        int count=0;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                if(arr1[i]==arr2[j]){
                    count++;
                }
            }
        }
        return count;
    }
    //方法3：判断两个数字是否相等（蓝球）
    public static int bluecount(int num1,int num2){
        int count=0;
        if(num1==num2){
            count=1;}
        else {count=0;}
        return count;
    }
    //方法4：计算奖金
    public static void bonus(int redidentnum,int blueidentnum) {
        if (blueidentnum == 0) {
            switch (redidentnum) {
                case 1 -> System.out.println("0元");
                case 2 -> System.out.println("0元");
                case 3 -> System.out.println("0元");
                case 4 -> System.out.println("10元");
                case 5 -> System.out.println("200元");
                case 6 -> System.out.println("500万元");
                case 0 -> System.out.println("0元");
            }
        } else if (blueidentnum == 1) {
            switch (redidentnum) {
                case 1 -> System.out.println("5元");
                case 2 -> System.out.println("5元");
                case 3 -> System.out.println("10元");
                case 4 -> System.out.println("200元");
                case 5 -> System.out.println("3000元");
                case 6 -> System.out.println("1000万元");
                case 0 -> System.out.println("5元");
            }
        }
    }
}

